import React, { Component } from 'react'

class Child extends Component {
    state = {
        title: 'Child'
    }
    render() {
        return (<div>
            {this.state.title}
        </div>)
    }
    componentWillReceiveProps(nextProps) {
        //TODO:父组件更新时，最先获得父组件的数据
        console.log('componentWillReceiveProps',nextProps)
        this.setState({title: nextProps.text})
    }
}
export default class App extends Component {
    state={text:'11'}
  render() {
    return (
      <div>
          <button onClick={() => this.setState({text:'222'})}>click</button>
          <Child text={this.state.text}/>
      </div>
    )
  }
}
